{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 对活动进行聚类\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "## 导入工具包\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "#特征编码\n",
    "from utils import FeatureEng\n",
    "\n",
    "from sklearn.preprocessing import normalize\n",
    "from sklearn import metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#读取数据\n",
    "import scipy.io as sio\n",
    "eventContMatrix = sio.mmread(\"EV_eventContMatrix\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.cluster import MiniBatchKMeans\n",
    "\n",
    "# 一个参数点（聚类数据为K）的模型，并评价聚类算法性能\n",
    "def K_cluster_analysis(K, df):\n",
    "    print(\"K-means begin with clusters: {}\".format(K));\n",
    "    \n",
    "    #K-means,在训练集上训练\n",
    "    km = MiniBatchKMeans(n_clusters = K)\n",
    "    km.fit(df)\n",
    "    \n",
    "    #保存预测结果\n",
    "    cluster_result = km.predict(df)\n",
    "\n",
    "    # K值的评估标准\n",
    "    #常见的方法有轮廓系数Silhouette Coefficient和Calinski-Harabasz Index\n",
    "    #这两个分数值越大则聚类效果越好\n",
    "    #CH_score = metrics.calinski_harabaz_score(X_train,mb_kmeans.predict(X_train))\n",
    "    CH_score = metrics.silhouette_score(df,cluster_result)   \n",
    "    print(\"CH_score: {}\".format(CH_score))\n",
    "\n",
    "    return CH_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "K-means begin with clusters: 10\n",
      "CH_score: 0.0893369452561\n",
      "K-means begin with clusters: 20\n",
      "CH_score: 0.129274618503\n",
      "K-means begin with clusters: 30\n",
      "CH_score: 0.0280184008785\n",
      "K-means begin with clusters: 40\n",
      "CH_score: -0.0817674741885\n",
      "K-means begin with clusters: 50\n",
      "CH_score: -0.0868064194754\n",
      "K-means begin with clusters: 60\n",
      "CH_score: -0.22764313025\n",
      "K-means begin with clusters: 70\n",
      "CH_score: -0.216453539471\n",
      "K-means begin with clusters: 80\n",
      "CH_score: -0.0365950987746\n",
      "K-means begin with clusters: 90\n",
      "CH_score: -0.051676027788\n",
      "K-means begin with clusters: 100\n",
      "CH_score: -0.0385504977526\n"
     ]
    }
   ],
   "source": [
    "# 设置超参数（聚类数目K）搜索范围\n",
    "CH_scores = []\n",
    "Ks = [10,20,30,40,50,60,70,80,90,100]\n",
    "for K in Ks:\n",
    "    ch = K_cluster_analysis(K, eventContMatrix)\n",
    "    CH_scores.append(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "print CH_scores"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x118b88e10>]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xl4lOW5x/HvzSoqCEJABBWoiCKI\nS4rYKloFxWpFK+J2lKqItVpjFRVte9qiHnEvri1uxX0URain1QoVcaUGqyxuUBBBUaKgIqAI3OeP\n581JJiRkmeWdyfw+1zVXMjPPzNwZhvzyPttr7o6IiEi5JnEXICIiuUXBICIiSRQMIiKSRMEg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/WdDwW6AzsC2xC6S6oqlM9G\nbTL2/0bBkAVm1pwQCg+5+5PRzZ+WH/ZFX1fEVV+W/RA4xsw+AB4ldBP8kXAY3Cxq0xX4OJ7ysm4Z\nsMzdZ0XXJxGCohA/H4OAxe5e5u7fAU8CP6BwPxvlavosLAN2qtQube+NgiHDov7ze4B33P2mSndN\nBUZE348ApmS7tji4++Xu3tXduxEGFv/p7qcCzwPDomaF9H58Aiw1s17RTYcBb1OYn48PgQFmtnX0\n/6b8vSjIz0YlNX0WpgKnR7OTBgBflnc5pUoL3DLMzA4EXgTmUtGnfgVhnOExYGfCf4gT3L3qoFOj\nZmaHAKPd/Wgz60E4gtge+DfwX+7+bZz1ZYuZ7U0YiG8BLALOIPzRVnCfDzP7A3AiYTbfv4GRhH7z\ngvhsmNkjwCGEXVQ/BX4HPEU1n4UoPG8jzGJaC5zh7qVpqUPBICIilakrSUREkigYREQkiYJBRESS\nKBhERCSJgkFERJIoGEREJImCQUREkigYREQkyf8BSQ+XXBq9olwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x117ee5250>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 绘制不同PCA维数下模型的性能，找到最佳模型／参数（分数最高）\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "plt.plot(Ks, np.array(CH_scores), 'b-')"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
